package aopDemo;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
//切面类
public class CommentAOP {
    public Object around(ProceedingJoinPoint point) throws Throwable {
        System.out.println("环绕开始：执行目标方法前-around-advise-start");
        Object object=point.proceed();
        System.out.println("环绕结束：执行目标方法后-around-advise-end");
        return object;
    }

    public void before(JoinPoint point) {
        System.out.println("before-advise-前置通知方法执行了，增强的方法名："+point.getSignature().getName());
        Object[] objects=point.getArgs();
        for (Object arg : objects) {
            if (arg != null) {
                String input = (String) arg;
                if (input.contains("微信")) {
                    throw new IllegalArgumentException("检测到敏感词: 微信");
                }
            }
        }
    }


    public void after() {
        System.out.println("after-advise-后置通知");
    }

    public void afterReturning() {
        System.out.println("afterReturning-advise-后置返回通知");
    }

    public void afterThrowing() {
        System.out.println("afterThrowing-advise-抛出异常了");
    }
}
